from datetime import datetime
from time import sleep

from selenium.webdriver import Keys
from selenium.webdriver.common.by import By

from base.base import Base
from page import c_path

url = "http://192.168.8.222/admin.php"


class UserPage(Base):
    def __init__(self):
        super().__init__(url)

    def going_iframe_user(self):
        self.set_cookie("../data/c_admin_cookies.json")
        self.driver.get(url)  # 跳过登录
        self.click(c_path.user_management)  # 点击用户管理
        self.click(c_path.user_management_list)  # 点击用户列表菜单
        self.go_iframe(c_path.iframe_url)  # 进入iframe

    def add_mana_user(self, a, b, c, d, e, f, g, h, i, j):  # 新增用户
        self.going_iframe_user()
        self.click(c_path.add_mana_user)  # 点击新增按钮
        self.input(c_path.mana_username, a)  # 输入用户名
        self.input(c_path.mana_username1, b)  # 输入昵称
        self.input(c_path.mana_phone, c)  # 输入手机号码
        self.input(c_path.mana_email, d)  # 输入电子邮箱
        self.input(c_path.mana_openid, e)  # 输入QQopenid
        self.scroll(c_path.mana_scroll)
        self.input(c_path.mana_birthday, datetime.now().strftime(f))  # 选择生日
        self.input(c_path.mana_address, g)  # 输入详细地址
        self.click(c_path.mana_sex)  # 选择性别
        self.input(c_path.mana_integral, h)  # 输入积分
        self.input(c_path.mana_userid, i)  # 输入邀请用户id
        self.input(c_path.mana_pwd, j)  # 输入登录密码
        self.click(c_path.mana_btn)  # 点击保存按钮

    def update_mana_user(self, a, b, c):
        self.going_iframe_user()
        self.click(c_path.update_mana_btn)  # 点击修改按钮
        self.input(c_path.update_mana_username, a)  # 输入修改的用户名
        self.input(c_path.update_mana_address, b)  # 输入修改的地址
        self.click(c_path.update_mana_sex)  # 修改性别
        self.click(c_path.update_mana_stauts)  # 点击用户状态
        self.input(c_path.update_status_input, c)  # 输入状态
        self.find_element(c_path.update_status_input).send_keys(Keys.ENTER)
        self.click(c_path.mana_btn)  # 点击保存按钮

    def delete_mana_user(self):
        self.going_iframe_user()
        self.click(c_path.delete_mana)
        self.click(c_path.delete_mana_btn)


if __name__ == '__main__':
    ap = UserPage()
    # ap.add_mana_user()
    # ap.update_mana_user()
    ap.delete_mana_user()
    sleep(5)
